#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
    int a;
    int bai = 0;
    int shi = 0;
    int ge = 0;
    int times = 0;

    scanf("%d", &a);
    if (a > 6 || a <= 0) {
        scanf("%d", &a);
    }
    for (bai = a; bai <= a + 3; bai++) {
        for (shi = a; shi <= a + 3; shi++) {
            for (ge = a; ge <= a + 3; ge++) {
                if (bai != shi && shi != ge && bai != ge) {

                    times++;
                    if (times % 6 == 0) {

                        printf("%d", bai * 100 + shi * 10 + ge);
                        printf("\n");
                    }
                    else  printf("%d ", bai * 100 + shi * 10 + ge);
                }
            }
        }
    }
    return 0;
}